{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 第一题 两数求和",
   "id": "9d1de94a3eb7c555"
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-03-01T07:29:40.855278Z",
     "start_time": "2025-03-01T07:29:40.841034Z"
    }
   },
   "source": [
    "num1=20\n",
    "num2=21\n",
    "result=num1+num2\n",
    "print(result)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "41\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 第二题 找出100以内偶数",
   "id": "b3d5fc0a46a0dff4"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "",
   "id": "9ec7c7879b4b193"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T07:31:01.209358Z",
     "start_time": "2025-03-01T07:31:01.194629Z"
    }
   },
   "cell_type": "code",
   "source": [
    "for i in range(1,101):\n",
    "    if i%2==0:\n",
    "        print(i,end=\" \")"
   ],
   "id": "1fa070a692d58ffc",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 "
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T07:32:58.060496Z",
     "start_time": "2025-03-01T07:32:58.051715Z"
    }
   },
   "cell_type": "code",
   "source": [
    "list=[]\n",
    "for i in range(1,100):\n",
    "    if i%2==0:\n",
    "        list.append(i)\n",
    "print(list)"
   ],
   "id": "226bf122bf722c28",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98]\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 第三题 找出100以内奇数",
   "id": "5de0450c5e6e31c3"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T07:35:21.745930Z",
     "start_time": "2025-03-01T07:35:21.736939Z"
    }
   },
   "cell_type": "code",
   "source": [
    "list=[]\n",
    "for i in range(1,100):\n",
    "    if i%2==0:\n",
    "        continue\n",
    "    else:\n",
    "        list.append(i)\n",
    "print(list)"
   ],
   "id": "57215d86afc6f5ca",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99]\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T07:38:09.670823Z",
     "start_time": "2025-03-01T07:38:09.658444Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#方法1：\n",
    "list=[]\n",
    "for i in range(1,100):\n",
    "    if i%2!=0:\n",
    "        list.append(i)\n",
    "print(list)"
   ],
   "id": "26cdf2bfc16bdced",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99]\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T07:38:59.590422Z",
     "start_time": "2025-03-01T07:38:59.582530Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#方法2\n",
    "list=[]\n",
    "for i in range(1,100,2):\n",
    "    list.append(i)\n",
    "print(list)"
   ],
   "id": "55c8499e818e1ae2",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99]\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 第四题 判断素数\n",
   "id": "f3fb0d59ff5e39b8"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T08:00:38.226967Z",
     "start_time": "2025-03-01T08:00:35.684709Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# # #！！！input()返回的是字符串\n",
    "# n=int(input(\"请输入一个数\"))\n",
    "# if n==1:\n",
    "#     print(\"不是素数\")\n",
    "# elif n==0:\n",
    "#     print(\"不是素数\")\n",
    "# for i in range(2,n):\n",
    "#     if n%i==0:\n",
    "#          print(\"不是素数\")\n",
    "#          break\n",
    "#     else:\n",
    "#         print(\"是素数\")\n",
    " #有点问题......    \n",
    "\n",
    "        "
   ],
   "id": "74dcc18defed4c21",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "是素数\n",
      "是素数\n",
      "是素数\n",
      "不是素数\n"
     ]
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T08:09:10.210907Z",
     "start_time": "2025-03-01T08:09:06.036482Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a=int(input(\"请输入一个正整数\"))\n",
    "flag=False\n",
    "for i in range(2,a):\n",
    "    if a%i==0:\n",
    "        flag=True\n",
    "        break\n",
    "if flag:\n",
    "    print(\"不是素数\")\n",
    "else:\n",
    "    print(\"是素数\")\n"
   ],
   "id": "badd96d1404824b3",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "不是素数\n"
     ]
    }
   ],
   "execution_count": 24
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 第五题 求阶乘",
   "id": "5d6ad85e7daed83e"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T08:12:52.416717Z",
     "start_time": "2025-03-01T08:12:49.109638Z"
    }
   },
   "cell_type": "code",
   "source": [
    "n=1\n",
    "a=int(input(\"请输入一个自然数\"))\n",
    "for i in range(1,a+1):\n",
    "    n=n*i\n",
    "print(n)"
   ],
   "id": "cf16bfe43c173a46",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24\n"
     ]
    }
   ],
   "execution_count": 27
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T08:15:36.490219Z",
     "start_time": "2025-03-01T08:15:33.476971Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#方法1：非递归\n",
    "sum=1\n",
    "n=int(input(\"请输入一个整数\"))\n",
    "for i in range(1,n+1):\n",
    "    sum=sum*i\n",
    "print(sum)"
   ],
   "id": "b3a87f7dc5beb829",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "execution_count": 28
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T08:19:36.505790Z",
     "start_time": "2025-03-01T08:19:33.839990Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#方法2：递归!!!自己调自己\n",
    "n=int(input(\"请输入一个整数\"))\n",
    "def jie_cheng(num):\n",
    "    if num==1:\n",
    "        return 1\n",
    "    else:\n",
    "        return num*jie_cheng(num-1)\n",
    "print(jie_cheng(n))"
   ],
   "id": "8455ef3df77a1833",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "execution_count": 29
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 第六题 求圆的周长",
   "id": "6358cf6d9c2ef3eb"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T08:22:59.951799Z",
     "start_time": "2025-03-01T08:22:57.434483Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# Π怎么表示\n",
    "# r=int(input(\"请输入半径\"))\n",
    "# zhou_chang=r*2\n",
    "# print(zhou_chang)"
   ],
   "id": "d98614e0cebb85af",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "execution_count": 33
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T08:26:50.589564Z",
     "start_time": "2025-03-01T08:26:48.236502Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import math  #或者直接令pi=3.14\n",
    "r=float(input(\"请输入半径\"))\n",
    "zhou_chang=math.pi*2*r\n",
    "print(zhou_chang)"
   ],
   "id": "d67313aca560918d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6.283185307179586\n"
     ]
    }
   ],
   "execution_count": 35
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 第七题 求圆的面积",
   "id": "71e7dc7b50670795"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T08:30:10.210134Z",
     "start_time": "2025-03-01T08:30:06.094356Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import math\n",
    "r=float(input(\"请输入半径\"))\n",
    "s=r*r*math.pi\n",
    "print(f\"圆的面积为{s}\")"
   ],
   "id": "538e513976bd10a1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "圆的面积为3.141592653589793\n"
     ]
    }
   ],
   "execution_count": 36
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 第八题 求直角三角形斜边长",
   "id": "79323420e0a1a6aa"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T08:33:57.636055Z",
     "start_time": "2025-03-01T08:33:51.896016Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import math\n",
    "a=int(input(\"请输入边长\"))\n",
    "b=int(input(\"请输入另一条边长\"))\n",
    "c=math.sqrt(a*a+b*b)\n",
    "print(f\"斜边长为{c}\")\n"
   ],
   "id": "edf69e367bf8e39f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "斜边长为5.0\n"
     ]
    }
   ],
   "execution_count": 37
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 第九题 比较三个数大小\n",
   "id": "571001f124910fff"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "# a=int(input(\"请输入第一个数\"))\n",
    "# b=int(input(\"请输入第二个数\"))\n",
    "# c=int(input(\"请输入第三个数\"))\n",
    "# def __lt__(self,other):\n",
    "#     return a<b\n"
   ],
   "id": "90708b28ce7c0c1c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T09:06:48.445772Z",
     "start_time": "2025-03-01T09:06:38.043017Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a=int(input(\"请输入第一个数\"))\n",
    "b=int(input(\"请输入第二个数\"))\n",
    "c=int(input(\"请输入第三个数\"))\n",
    "list=[a,b,c]\n",
    "list1=sorted(list)\n",
    "print(f'三个数从小到大的顺序是{list1[0]},{list1[1]},{list1[2]}')"
   ],
   "id": "d8f41cb895031251",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "三个数从小到大的顺序是304,615,1212\n"
     ]
    }
   ],
   "execution_count": 38
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 第十题 找出区间内的素数",
   "id": "2450288939ff6ebc"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "5ab50f497758ed9c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T09:36:07.609424Z",
     "start_time": "2025-03-01T09:36:02.956455Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# list=[]\n",
    "# a=int(input(\"请输入第一个数\"))\n",
    "# b=int(input(\"请输入第二个数\"))\n",
    "# \n",
    "# for i in range(a,b+1):\n",
    "#     flag=False\n",
    "#     for j in range(2,i):\n",
    "#         if i%j!=0:\n",
    "#             list.append(i)\n",
    "#             \n",
    "#             \n",
    "# print(list)\n",
    "#             \n",
    "#   有点问题。。。。。。。。 \n",
    "\n",
    "list=[]\n",
    "a=int(input(\"请输入第一个数\"))\n",
    "b=int(input(\"请输入第二个数\"))\n",
    "\n",
    "for i in range(a,b+1):\n",
    "    if i>1:\n",
    "        flag=False\n",
    "        for j in range(2,i):\n",
    "            if i%j==0:\n",
    "                flag=True\n",
    "                break\n",
    "        if flag==False:\n",
    "                list.append(i)\n",
    "print(list)"
   ],
   "id": "b0a81d29b950566",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 7, 11, 13, 17, 19]\n"
     ]
    }
   ],
   "execution_count": 56
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T09:21:39.823452Z",
     "start_time": "2025-03-01T09:21:35.095453Z"
    }
   },
   "cell_type": "code",
   "source": "\n",
   "id": "6b9dc5aad1dc7042",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 7, 11, 13, 17, 19]\n"
     ]
    }
   ],
   "execution_count": 45
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-01T09:40:33.871554Z",
     "start_time": "2025-03-01T09:40:28.974974Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#判断n是否为素数\n",
    "def prime(n):\n",
    "    flag=True\n",
    "    for i in range(2,n):\n",
    "        if n%i==0:\n",
    "            flag=False\n",
    "            break\n",
    "    return flag\n",
    "\n",
    "list=[]    \n",
    "a=int(input(\"请输入第一个数\"))\n",
    "b=int(input(\"请输入第二个数\"))\n",
    "for j in range(a,b+1):\n",
    "    if prime(j):\n",
    "        list.append(j)\n",
    "print(list)"
   ],
   "id": "dd44411e8f77754f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 7, 11, 13, 17, 19]\n"
     ]
    }
   ],
   "execution_count": 57
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
